import json
import pickle


class Student():
    name = None
    age = 0

    def say_hi(self):
        print(f"大家好，我叫{self.name}")


student = Student()

student.name = "张三"
student.age = 19
student.say_hi()
# 将类对象序列化成json字符串输出
print(json.dumps(student.__dict__, ensure_ascii=False))

# 将json字符串反序列化成类对象
str = '{"name": "李四", "age": 33}'
destu = Student.__new__(Student)
destu.__dict__ = json.loads(str)
print(f"姓名：{destu.name}，年龄：{destu.age}")
destu.say_hi()
